﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;

namespace SPPivotViewer.Utility
{
    public  class logger:SPDiagnosticsServiceBase
    {    
        public static string PVViewerDiagnosticAreaName = "Pivot Viewer for SharePoint";    
        private static logger _Current;    
        public static logger Current    
        {        
            get        
            {
                if (_Current == null)
                {
                    _Current = new logger();
                }
                return _Current;
            }
        }
        private logger() : base("Pivot Viewer for SharePoint Logging Service", SPFarm.Local) { }
        protected override IEnumerable<SPDiagnosticsArea> ProvideAreas() 
        { 
            List<SPDiagnosticsArea> areas = new List<SPDiagnosticsArea> {
                new SPDiagnosticsArea(PVViewerDiagnosticAreaName, new List<SPDiagnosticsCategory> {
                    new SPDiagnosticsCategory("Document Image", TraceSeverity.Unexpected, EventSeverity.Error),
                    new SPDiagnosticsCategory("Image Provider Base", TraceSeverity.Unexpected, EventSeverity.Error),
                    new SPDiagnosticsCategory("Image Base", TraceSeverity.Unexpected, EventSeverity.Error),
                    new SPDiagnosticsCategory("Web Image", TraceSeverity.Unexpected, EventSeverity.Error),
                    new SPDiagnosticsCategory("CXML", TraceSeverity.Unexpected, EventSeverity.Error)
                }) 
            };
            return areas; 
        }
        public static void ErrorMessage(string categoryName, string errorMessage) 
        {
            SPDiagnosticsCategory category = logger.Current.Areas[PVViewerDiagnosticAreaName].Categories[categoryName];
            logger.Current.WriteTrace(0, category, TraceSeverity.Unexpected, errorMessage);
        }
        public static void InfoMessage(string categoryName, string errorMessage)
        {
            SPDiagnosticsCategory category = logger.Current.Areas[PVViewerDiagnosticAreaName].Categories[categoryName];
            logger.Current.WriteTrace(0, category, TraceSeverity.Verbose, errorMessage);
        }
        public static void WarnMessage(string categoryName, string errorMessage)
        {
            SPDiagnosticsCategory category = logger.Current.Areas[PVViewerDiagnosticAreaName].Categories[categoryName];
            logger.Current.WriteTrace(0, category, TraceSeverity.Medium, errorMessage);
        }
    }
}
